﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace RouterControlTest
{
	/// <summary>
	/// Summary description for SpecificationManagerTypeIdConvert
	/// </summary>
	[TestClass]
	public class SpecificationManager
	{
		private readonly string[] TypeIds = {
			"urn:schemas-upnp-org:device:InternetGatewayDevice:1",
			"urn:schemas-upnp-org:service:Layer3Forwarding:1",
			"urn:schemas-upnp-org:device:WANDevice:1",
			"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1",
			"urn:schemas-upnp-org:device:WANConnectionDevice:1",
			"urn:schemas-upnp-org:service:WANIPConnection:1",
			"urn:schemas-microsoft-com:service:OSInfo:1"
		};

		private readonly string[] MemberNames = {
			"InternetGatewayDevice1",
			"Layer3Forwarding1",
			"WANDevice1",
			"WANCommonInterfaceConfig1",
			"WANConnectionDevice1",
			"WANIPConnection1",
			"OSInfo1"
		};

		public SpecificationManager()
		{
			System.Diagnostics.Debug.Assert(TypeIds.Length == MemberNames.Length);
		}

		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		//
		// You can use the following additional attributes as you write your tests:
		//
		// Use ClassInitialize to run code before running the first test in the class
		// [ClassInitialize()]
		// public static void MyClassInitialize(TestContext testContext) { }
		//
		// Use ClassCleanup to run code after all tests in a class have run
		// [ClassCleanup()]
		// public static void MyClassCleanup() { }
		//
		// Use TestInitialize to run code before running each test 
		// [TestInitialize()]
		// public void MyTestInitialize() { }
		//
		// Use TestCleanup to run code after each test has run
		// [TestCleanup()]
		// public void MyTestCleanup() { }
		//
		#endregion

		[TestMethod]
		public void TypeIdToMemberName()
		{
			for (int i = 0; i < TypeIds.Length; i++)
			{
				var orig = TypeIds[i];
				var exp = MemberNames[i];

				Assert.AreEqual(exp, RouterControl.IO.Specification.SpecificationManager.TypeIdToMemberName(orig));
			}
		}

		[TestMethod]
		public void GetFullSpecification()
		{
			var str = RouterControl.IO.Specification.SpecificationManager.Instance.GetFullSpecification(RouterControl.IO.RootDeviceTypeIds.InternetGatewayDeviceType);

			Console.WriteLine(str.OwnerDocument.OuterXml);
		}

		[TestMethod]
		public void GetFullSpecificationDom()
		{
			var dom = RouterControl.IO.Specification.SpecificationManager.Instance.GetFullSpecificationDom(RouterControl.IO.RootDeviceTypeIds.InternetGatewayDeviceType);

			Console.WriteLine(dom.ToXml());
		}

		[TestMethod]
		public void CompileFullSpecificationDom()
		{
			var dom = RouterControl.IO.Specification.SpecificationManager.Instance.GetFullSpecificationDom(RouterControl.IO.RootDeviceTypeIds.InternetGatewayDeviceType);

			Console.WriteLine(dom.ToXml());

			var g = new RouterControl.IO.Specification.DeviceServiceCompiler(new RouterControl.IO.Specification.ServiceInterfaceCompilerVariation());

			g.AddServicesAll(dom.GetAllServices());

			Console.WriteLine(g.GetCsharpCode());
		}

	}
}
